from dailyspents.model import orm
from dailyspents._exceptions import DatabaseException
from sqlalchemy.exceptions import *
from sqlalchemy.ext.selectresults import SelectResults
from GenericController import GenericController

class PaymentController(GenericController):
    
    def __init__(self, user):
        GenericController.__init__(self, user, orm.Payment)
        
    def getAll(self):
        res = SelectResults(self.query)
        res = res.order_by(orm.Payment.c.name)
        res = res.filter(orm.Payment.c.user_id == self.user.id)
        return list(res)
    
    def getByName(self, name_):
        return self.query.get_by(name = name_, user=self.user)
